package com.luli.controllor;

import com.alibaba.fastjson.JSON;
import com.luli.entity.photo.Photo;
import com.luli.entity.response.ResponseMsg;
import com.luli.entity.tree.CatalogVO;
import com.luli.service.TreeService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.luli.Utils.ResponseMsgUtil.getFailMsg;
import static com.luli.Utils.ResponseMsgUtil.getSuccessMsg;

/**
 * 陆离
 * 2022/7/30 17:29:41
 */
@RestController
@Slf4j
@RequestMapping("/tree")
@CrossOrigin
public class TreeController {

    @Autowired
    private TreeService treeService;

    @RequestMapping(value = "/getTree", method = RequestMethod.GET)
    public ResponseMsg<?> getTree() {
        try {
            List<CatalogVO> tree = treeService.getTree();
            return getSuccessMsg(null, "查询成功", tree);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return getFailMsg(null, "查询失败", e.getMessage());
        }
    }



    @RequestMapping(value = "/getTreeMap", method = RequestMethod.GET)
    public ResponseMsg<?> getTreeMap() {
        try {
            List<Map<String, Object>> treeMaps = treeService.getTreeMaps();
            return getSuccessMsg(null, "查询成功", treeMaps);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return getFailMsg(null, "查询失败", e.getMessage());
        }
    }

    public static void main(String[] args) {
        String json = "[{deptName=教育厅, deptId=1864580147940745217, childMenus=[], ancestors=0, parentId=0}, {deptName=人事部门, deptId=1864589303087112193, childMenus=[], ancestors=0,1864580147940745217, parentId=1864580147940745217}, {deptName=社会保障部, deptId=1864602148193546242, childMenus=[], ancestors=0,1864580147940745217, parentId=1864580147940745217}, {deptName=社会保障局, deptId=1864602657142976514, childMenus=[], ancestors=0,1864580147940745217, parentId=1864580147940745217}, {deptName=后勤保障局, deptId=1864602726013448194, childMenus=[{deptName=后勤1组, deptId=1864602757651083266, childMenus=[], ancestors=0,1864580147940745217,1864602726013448194, parentId=1864602726013448194}, {deptName=后勤二组, deptId=1864602801221513217, childMenus=[], ancestors=0,1864580147940745217,1864602726013448194, parentId=1864602726013448194}], ancestors=0,1864580147940745217, parentId=1864580147940745217}, {deptName=后勤1组, deptId=1864602757651083266, childMenus=[], ancestors=0,1864580147940745217,1864602726013448194, parentId=1864602726013448194}, {deptName=后勤二组, deptId=1864602801221513217, childMenus=[], ancestors=0,1864580147940745217,1864602726013448194, parentId=1864602726013448194}]";
        System.out.println(JSON.toJSONString(json));
    }
}
